package top.sdaily.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.sdaily.core.mybatis.Conditions;
import top.sdaily.core.utils.IdGeneratorUtils;
import top.sdaily.mapper.ProvinceMapper;
import top.sdaily.web.model.Province;
import top.sdaily.web.service.ProvinceService;

import java.util.List;

/**
 * Created by TsujiShiki on 2017/02/17.
 */
@Service
@Transactional
public class ProvinceServiceImpl implements ProvinceService {

    @Autowired
    private ProvinceMapper provinceMapper;

    @Override
    public List<Province> getAllProvince() {
        return provinceMapper.findList(new Conditions(Province.class));
    }

    @Override
    public Province getProvinceById(String id) {
        return provinceMapper.findOne(new Conditions(Province.class).id(id));
    }

    @Override
    public int insertProvince(Province province) {
        province.setPkid(IdGeneratorUtils.fresh());
        return provinceMapper.insert(province);
    }

    @Override
    public int updateProvince(Province province) {
        return provinceMapper.update(province);
    }
}
